package nc.impl.mmpac.sumpickm;

import java.util.List;

import nc.bs.mmpac.sumpickm.bp.query.SumPickmQueryBP;
import nc.bs.mmpac.sumpickm.bp.query.SumPickmSumDimQueryBP;
import nc.itf.mmpac.sumpickm.ISumPickmQueryService;
import nc.ui.querytemplate.querytree.IQueryScheme;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.mmpac.pickm.entity.PickmViewVO;
import nc.vo.mmpac.sumpickm.entity.AggSumPickmVO;
import nc.vo.mmpac.sumpickm.entity.SumPickmHeadVO;
import nc.vo.mmpac.sumpickm.entity.SumPickmSumDimVO;
import nc.vo.mmpac.sumpickm.entity.SumPickmSumVO;
import nc.vo.mmpac.sumpickm.vochange.SumPickmToPickmViewVoChange;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public class SumPickmQueryServiceImpl implements ISumPickmQueryService {

    @Override
    public AggSumPickmVO[] queryByQueryScheme(IQueryScheme queryScheme, Integer prodmode) throws BusinessException {
        try {
            SumPickmQueryBP bp = new SumPickmQueryBP();
            return bp.query(queryScheme, prodmode);
        }
        catch (Exception e) {
            ExceptionUtils.marsh(e);
        }
        return null;
    }

    @Override
    public SumPickmSumDimVO querySumDimVO(String pk_group, String pk_org, String userid) throws BusinessException {
        SumPickmSumDimVO retVO = null;
        try {
            SumPickmSumDimQueryBP query = new SumPickmSumDimQueryBP();
            retVO = query.querySumDimVOByUser(pk_group, pk_org, userid);
            return retVO;
        }
        catch (Exception e) {
            ExceptionUtils.marsh(e);
        }
        return retVO;
    }

    @Override
    public SumPickmHeadVO[] queryHeadVOsByHeadIDs(String[] headIDs) throws BusinessException {
        if (MMValueCheck.isEmpty(headIDs)) {
            return null;
        }
        try {
            SumPickmQueryBP bp = new SumPickmQueryBP();
            return bp.queryHeadVObyIds(headIDs);
        }
        catch (Exception e) {
            ExceptionUtils.marsh(e);
        }
        return null;
    }

    @Override
    public SumPickmSumVO[] querySumVOsBySumIDs(String[] sumIDs) throws BusinessException {
        if (MMValueCheck.isEmpty(sumIDs)) {
            return null;
        }
        try {
            SumPickmQueryBP bp = new SumPickmQueryBP();
            return bp.querySumVObySids(sumIDs);
        }
        catch (Exception e) {
            ExceptionUtils.marsh(e);
        }
        return null;
    }

    @Override
    public AggSumPickmVO[] queryWithSumByIds(String[] ids) throws BusinessException {
        SumPickmQueryBP bp = new SumPickmQueryBP();
        return bp.queryAggVOWithSumByIds(ids);
    }

    @Override
    public AggSumPickmVO[] queryWithDetailByIds(String[] ids) throws BusinessException {
        SumPickmQueryBP bp = new SumPickmQueryBP();
        return bp.queryAggVOWithDetailByIds(ids);
    }

    @Override
    public PickmViewVO[] querySumPickmViewVOs(String[] sumIDs) throws BusinessException {
        if (MMValueCheck.isEmpty(sumIDs)) {
            return null;
        }
        SumPickmQueryBP bp = new SumPickmQueryBP();
        AggSumPickmVO[] aggvos = bp.queryAggVOWithSumBySids(sumIDs);
        if (MMValueCheck.isEmpty(aggvos)) {
            return null;
        }
        SumPickmToPickmViewVoChange change = new SumPickmToPickmViewVoChange();
        return change.transToPickmViewVO(aggvos);
    }

    @Override
    public PickmViewVO[] transToPickmViewVO(List<String> hids) throws BusinessException {
        if (MMValueCheck.isEmpty(hids)) {
            return null;
        }
        SumPickmQueryBP bp = new SumPickmQueryBP();
        AggSumPickmVO[] aggvos = bp.queryAggVObyHids(hids.toArray(new String[0]));

        if (MMValueCheck.isEmpty(aggvos)) {
            return null;
        }
        SumPickmToPickmViewVoChange change = new SumPickmToPickmViewVoChange();
        return change.transToPickmViewVO(aggvos);
    }

}
